<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>直线连用</title>
</head>

<body>
  <canvas id="line" width="500" height="500"></canvas>

  <script>
    const canvas = document.querySelector('#line')
    const ctx = canvas.getContext('2d')

    ctx.lineWidth = 10
    ctx.strokeStyle = '#f40'
    ctx.beginPath()
    ctx.moveTo(100, 100)
    ctx.lineTo(400, 100)
    ctx.lineTo(400, 400)
    ctx.lineTo(100, 400)
    ctx.lineTo(100, 100)

    ctx.stroke()
    ctx.closePath()
  </script>

</body>

</html>